﻿using AutoMapper;
using FC.ERP.TMom.Api.AppHandlers.Commands.EssentialDatas.FactoryManages.Workstations;
using FC.ERP.TMom.Domain;
using FC.ERP.TMom.ErrorCode;
using FC.ERP.TMom.Infrastructure.Interfaces;
using MediatR;

namespace FC.ERP.TMom.Api.AppHandlers.CommandHandlers.EssentialDatas.FactoryManages.Workstations
{
    public class WorkstationAddCommandHandler : IRequestHandler<WorkstationAddCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Workstation> workstationrepository;
        private readonly IMapper mapper;
        public WorkstationAddCommandHandler(IBaseRepository<Workstation> workstationrepository, IMapper mapper)
        {
            this.workstationrepository = workstationrepository;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(WorkstationAddCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();
            var entity = mapper.Map<Workstation>(request);
            await workstationrepository.Add(entity);
            return await Task.FromResult(result);
        }
    }
}
